package cn.kgc.exception.Work03;

public class Uses extends User implements UseBiz{
    public static User [] users = new User[6];
    static {
        users[0]=new User("admin","123456", "张三","admin@123.com");
        users[1] = new User("tom","123456","李四","tomcat@cat.com");
    }

    public Uses() {
    }

    public Uses(String useName, String password, String realName, String email) {
        super(useName, password, realName, email);
    }

    @Override
    public void register(String username, String password, String rePassword, String name, String email) throws IllegalRegisterException {
        for(int i = 0;i<users.length;i++) {
            if(password.equals(rePassword) && !(users[i].getUseName().equals(name))) {
                System.out.println("注册成功！");
            }
            for(int j = 0 ; j < users.length;j++) {
                if(users[j] == null) {
                    users[j] = new User(username, password,name,email);
                    return;
                }
            }
            if(!(password.equals(rePassword))) {
                throw new IllegalRegisterException("两次输入的密码不一致！");
            }
            if(users[i].getUseName().equals(name)) {
                throw new IllegalRegisterException("用户名已存在！");
            }
        }

    }

    @Override
    public void login(String username, String password) throws IllegalLoginException {
        for(int i = 0;i < users.length;i++) {
            if(username.equals(users[i].getUseName()) && password.equals(users[i].getPassword()))   {
                System.out.println("登录成功！");
                return ;
            }
            else if(username.equals(users[i].getUseName()) && !(password.equals(users[i].getPassword())))  {
                System.out.println("密码不正确！");
                throw new IllegalLoginException("Fuck man!");
            }

        }

    }
    }

